package org.agilelang.editor.syntaxtext.dialogpopup;

/*
 AgileLang - A fourth generation language(http://www.agilelang.org).

 Copyright (C) 2013 Roderick Cusirramos (roderick20@hotmail.com)

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

import javax.swing.JComboBox;
import javax.swing.JTextField;

public class DlgScaffoldAddAttribute extends DialogBase {

    String[] str_type = {"binary", "boolean", "date", "datetime", "decimal", "float", "double", "integer", "int", "string", "text", "time", "timestamp", "datetime"};
    JComboBox name_model = new JComboBox();
    JTextField name = new JTextField(25);
    JTextField caption = new JTextField(25);
    JComboBox type = new JComboBox(str_type);
    JTextField length = new JTextField(25);
    JComboBox notnull = new JComboBox();
    JTextField defaultvalue = new JTextField(25);
    JTextField description = new JTextField(25);

    public DlgScaffoldAddAttribute() {
        super("Scaffold : addAttribute()", 9);
        initComponents();
        initUI();
    }

    private void initComponents() {
        notnull.addItem("yes");
        notnull.addItem("not");

        this.addLineTxt("Model", name_model);
        this.addSapce();
        this.addLineTxt("name", name);
        this.addLineTxt("caption", caption);
        this.addLineTxt("type", type);
        this.addLineTxt("length", length);
        this.addLineTxt("notnull", notnull);
        this.addLineTxt("defaultvalue", defaultvalue);
        this.addLineTxt("description", description);
    }

    public String getSentences() {
        return "Scaffold." + name_model.getSelectedItem().toString() + ".addAttribute(\n"
                + "  name =\"" + name.getText() + "\",\n"
                + "  caption =\"" + caption.getText() + "\",\n"
                + "  type =\"" + type.getSelectedItem().toString() + "\","
                + "  length =\"" + length.getText() + "\",\n"
                + "  notnull =\"" + notnull.getSelectedItem().toString() + "\",\n"
                + "  defaultvalue =\"" + defaultvalue.getText() + "\",\n"
                + "  description =\"" + description.getText() + "\" \n"
                + ");\n";
    }

    public void setNameModels(String[] items) {
        int size = items.length;
        for (int i = 0; i < size; i++) {
            name_model.addItem(items[i]);
        }
    }
}